#include "Widget.h"
#include"WaterProgressBar.h"
#include<QTimer>
#include<QDebug>
#include<QPainter>
#include<QPaintEvent>
#include<QPainterPath>
Widget::Widget(QWidget *parent)
    :QWidget(parent)
{
    resize(640,480);
    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
    WaterProgressBar* bar= new WaterProgressBar(this);
    QTimer* timer= new QTimer(this);
    bar->setRange(-100,100);
    timer->callOnTimeout(this,[=]()
    {
        static int i=-100;
        bar->setValue(i);
        //i=(i+1)%101;
        i++;
        phi+=0.25;
        if(phi== 360)
        {
            phi=0;
        }
        update();
    });
    timer->start(30);
    connect(bar,&WaterProgressBar::valueChanged,this,[](int value)
    {
        qInfo()<<"Value:"<<value;

    });
}

void Widget::paintEvent(QPaintEvent *ev)
{
    //QPainter painter(this);
    //QPainterPath path;
    //painter.setRenderHint(QPainter::RenderHint::Antialiasing);
    //for (int x = 0; x < 480; x++)
    //{
    //    path.lineTo(x,6*sin(0.025*x+phi)+200);

    //}
    //painter.drawPath(path);
}
